var AesUtil = function () {
    this.iterationCount = 1000;
    this.keySize = 128/32;
}

AesUtil.prototype.generateKey = function(salt) {
    var key = CryptoJS.PBKDF2("123456",
        CryptoJS.enc.Hex.parse(salt),
        { keySize: this.keySize, iterations: this.iterationCount });
    return key;
}

AesUtil.prototype.encrypt = function(salt, iv, data) {
    var key = this.generateKey(salt);
    var ivSpec = CryptoJS.enc.Hex.parse(iv);
    var encryptObj = CryptoJS.AES.encrypt(data, key, {
        iv: ivSpec,
        padding: CryptoJS.pad.Pkcs7,
        model:CryptoJS.mode.CBC
    });
     return encryptObj.ciphertext.toString(CryptoJS.enc.Base64);
}

AesUtil.prototype.decrypt = function(salt, iv, data) {
    var key = this.generateKey(salt);
    var ivSpec = CryptoJS.enc.Hex.parse(iv);

    var cipherParams = CryptoJS.lib.CipherParams.create({
        ciphertext: CryptoJS.enc.Base64.parse(data)
    });

    var decryptObj =  CryptoJS.AES.decrypt(cipherParams, key, {
        iv: ivSpec,
        padding: CryptoJS.pad.Pkcs7,
        model:CryptoJS.mode.CBC
    });
    return decryptObj.toString(CryptoJS.enc.Utf8);
}

AesUtil.prototype.random = function () {
    return CryptoJS.lib.WordArray.random(128/8).toString(CryptoJS.enc.Hex);
}